package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.sercice.PaymentHystrixService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
//@DefaultProperties(defaultFallback = "payment_Global_fallbackMethod")
public class PaymentHystrixController {
    @Resource
    PaymentHystrixService paymentHystrixService;

    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String payment_ok(@PathVariable("id") Integer id) {
        return paymentHystrixService.payment_ok(id);
    }

    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
//    @HystrixCommand(fallbackMethod = "paymentTimeOutHandle", commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000")
//    })
    @HystrixCommand
    public String payment_false(@PathVariable("id") Integer id) {
        return paymentHystrixService.payment_false(id);
    }

    public String paymentTimeOutHandle(@PathVariable("id") Integer id) {
        return "我是消费端hystrix， 请稍后再试！";
    }

    public String payment_Global_fallbackMethod() {
        return "请稍后再试！我是默认hystrix配置!";
    }
}
